package com.mall.shopping.services;

import com.mall.shopping.NavigationService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.PanelContentDto;
import com.mall.shopping.dto.PanelContentResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

//导航栏显示


@Component
@Service(interfaceClass = NavigationService.class)
public class NavigationImp implements NavigationService {

    @Autowired
    PanelContentMapper panelContentMapper;

    @Override
    public PanelContentResponse getNavigation() {
        Example example = new Example(PanelContent.class);
        example.setOrderByClause("sort_order");
        example.createCriteria().andEqualTo("panelId", 0);
        List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
        List<PanelContentDto> panelContentDtoList = new ArrayList<>();
        for (PanelContent panelContent : panelContents) {
            PanelContentDto panelContentDto = new PanelContentDto();
            panelContentDto.setId(panelContent.getId());
            panelContentDto.setPanelId(panelContent.getPanelId());
            panelContentDto.setType(panelContent.getType());
            panelContentDto.setSortOrder(panelContent.getSortOrder());
            panelContentDto.setFullUrl(panelContent.getFullUrl());
            panelContentDto.setProductId(panelContent.getProductId());
            panelContentDto.setPicUrl(panelContent.getPicUrl());
            panelContentDto.setPicUrl2(panelContent.getPicUrl2());
            panelContentDto.setPicUrl3(panelContent.getPicUrl3());
            panelContentDtoList.add(panelContentDto);
        }

        PanelContentResponse response = new PanelContentResponse();
        response.setPanelContentDtoList(panelContentDtoList);
        response.setCode(ShoppingRetCode.SUCCESS.getCode());
        response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return response;
    }
}
